 <?php
	
require_once  __DIR__ . '/includes/authenticate.php';

if (isset($_POST['season'])){  
	include_once './db_bb_connect.php';
	$username = $_SESSION['username'];
	
?>

<Script>
	//document.getElementByClassName("selected-season").innerHTML = <?php  //echo $_POST['season']; ?>;
	function setSeason(){
	document.getElementById("selected-season").innerHTML = "Season <?= $_POST['season']; ?> is selected";
}
	setSeason();

</Script>

<style type="text/css">
	#staff {
		background:black;
		width:200px;
		height:250px;
		color:white;
		border-radius:5px;
		float:left;
		margin:25px;
		font-size:22px;
		
	}

	#stafftitle{
		text-align: center;
	}

	#staffpic {
		width:100%;
		height:80%;
		float:top;
	}
	
	#staffpic {
		width:100%;
		height:80%;
		float:top;
	}
	
	#staffpic img {
		width:100%;
		height:100%;
	}

	#staffname {
		width:100%;
		line-height:50px;
		text-align:center;
		background:black;
		color:white;
		float:left;
		border-bottom-left-radius:5px;
		border-bottom-right-radius:5px;
		text-align: center;
	}

	#player {
		background:darkred;
		width:200px;
		height:250px;
		color:yellow;
		border-radius:5px;
		float:left;
		margin:25px;
		font-size:22px;
	}

	#playertitle{
		text-align: center;

	}

	#playerpic {
		width:100%;
		height:80%;
		float:top;
	}

	#playerpic img {
		width:100%;
		height:100%;
	}

	#playername {
		width:80%;
		line-height:50px;
		text-align:center;
		background:yellow;
		color:darkred;
		float:left;
		border-bottom-left-radius:5px;
	}



	#playernumber {
		width:20%;
		line-height:50px;
		text-align:center;
		background:yellow;
		color:darkred;
		float:left;
		border-bottom-right-radius:5px;
	}


</style>

<?php
	$season = $_POST['season']; ?>

<div class="text-center"><h2> Team of <?= $season; ?> </h2></div>
<div id="coaches"><h3>Technical Staff</h3>
<div class="row">
<div class="col-md-12">
<?php

	$sql = "SELECT firstname, lastname, playernumber
	FROM users 
	WHERE type = 'Coach' 
	ORDER BY playernumber";

	$result = $db->query($sql);

	while ($row = $result->fetch_assoc()){
		$firstname = $row['firstname'];
		$lastname = $row['lastname'];
		$playernumber = $row['playernumber'];

		echo "<div id='staff'>";
		if ($playernumber == '1'){
			echo "<div id='stafftitle'> Head Coach </div>";
		 }

		else if ($playernumber == '2'){
			echo "<div id='stafftitle'>Assistant </div>";
		 }

		else if ($playernumber == '3'){
			echo "<div id='stafftitle'> Team Manager </div>";
		 }

		echo "<div id='staffpic'> <img class='img-circle' width=100px src='./images/". strtolower($firstname) . "_" . strtolower($lastname) . ".jpeg'/> </div>";
		echo "<div id='staffname'>";
		echo "<strong> $firstname </strong>";
		echo "</div>";
		echo "</div>";

		//echo "<br>";
		
		

	} ?>

</div> </div> </div>
<br>

<div id="players"><h3>Players</h3>

<div class="row">
<div class="col-md-12">

<?php

	$sql = "SELECT users.firstname, users.lastname, teams.playernumber, users.position
	FROM users 
	JOIN teams 
	ON users.user_key = teams.playerID 
	WHERE teams.season = '$season' 
	ORDER BY teams.playernumber";

	$result = $db->query($sql);

	while ($row = $result->fetch_assoc()){
		$firstname = $row['firstname'];
		$lastname = $row['lastname'];
		$playernumber = $row['playernumber'];
		$position = ucfirst($row['position']);
		
		echo "<div id='player'>";
		echo "<div id='playertitle'> $position </div>";
		echo "<div id='playerpic'> <img class='img-circle' width=100px src='./images/". strtolower($firstname) . "_" . strtolower($lastname) . ".jpeg'/> </div>";
		echo "<div id='playername'>";
		echo "<strong> $firstname </strong>";
		echo "</div>";
		echo "<div id='playernumber'>";
		echo "<strong> $playernumber </strong>";
		echo "</div>";
		echo "</div>";
		
	}

}
?>

</div>

</div>
<br><br>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>